<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<style>
    	/* td .layui-form-select {
	     margin-top: -10px;
	     margin-left: -15px;
	     margin-right: -15px;
	 } */

     .layui-form-item .layui-inline{
        margin-right: -10px;
     }

     /* .layui-input{
        height: 100%;
     } */
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
     <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">conclusion</label>
                <div class="layui-input-inline">
                    <input type="text" name="report" placeholder="Fill in the conclusion"  autocomplete="off"  class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">personnel</label>
                <div class="layui-input-inline">
                    <input type="text" name="experimenter" placeholder="Fill in the tester"  autocomplete="off"  class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">Auditor</label>
                <div class="layui-input-inline">
                    <input type="text" name="auditors" placeholder="Please fill in the reviewer"  autocomplete="off"  class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">Date</label>
                <div class="layui-input-inline">
                    <input type="text" name="datetime" placeholder="Date of experiment"  autocomplete="off"  class="layui-input">
                </div>
            </div>
        </div>
        <div id="Myloading"><img src="../../lib/layui-v2.5.5/css/modules/layer/default/loading-01.gif" alt=""></div>

        <!-- 选项卡 -->
            <div class="layui-card">
                <!-- <div class="layui-card-header">设备检修</div> -->
                <div class="layui-card-body">
                <div class="layui-tab layui-tab-brief" lay-filter="tab-all">
                    <ul class="layui-tab-title" id="html_title" style="margin-bottom: 19px;"></ul>
                   
                    <div class="layui-tab-content" id="html_content"> </div>
                   
                </div>
                </div>
            </div>

            <script type="text/html" id="currentTableBar">
                <a lay-event="edit" ><img src="../../images/icon-qxt.png" alt=""></a>
            </script>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn" style="margin-left: 85%;">Update and save</button>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form','element', 'table','miniTab'], function () {
        // 2020-03-25 HF 保存token
        var token = sessionStorage.getItem('newtoken');
        var big_data = JSON.parse(sessionStorage.getItem('HsaveBig_check')) ;
        var $ = layui.jquery,
            form = layui.form,
            ele = layui.element,
            miniTab = layui.miniTab,
            table = layui.table;
            miniTab.listen();

            var html_title = '';
            var experimentMap = null;
            var experimentMap_check = null;
            var html_content = '';

            form.on('submit(saveBtn)', function (data) {
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                // 最后的表格数据填充
                experimentMap_check.auditors = data.field.auditors;
                experimentMap_check.datetime = data.field.datetime;
                experimentMap_check.experimentMap = experimentMap;
                experimentMap_check.experimenter = data.field.experimenter;
                experimentMap_check.report = data.field.report;

                layer.confirm('Are you sure to update the data?', {
                        btn: ['confirm','cancel'] //按钮
                        }, function(){
                            $.ajax({          
                                    url: '/oms-web/examines/save/authority?token='+ token,
                                    dataType:"json",  
                                    type:"post", 
                                    data:JSON.stringify(experimentMap_check),
                                    contentType:"application/json",
                                    success:function(data){
                                        if(data.code === 0){
                                                layer.msg(data.msg,{icon: 1,time:1500},function(){
                                                    parent.layer.close(iframeIndex);
                                                    window.parent.location.reload();//修改成功后刷新父界面
                                              })
                                        }else{
                                            layer.msg(data.msg,{icon: 1,time:1000});
                                        }
                                },
                                    error:function () {
                                        layer.msg("Data request error!");
                                    }
                            });
                  });
        });

// 获取头表  类型
            $.ajax({          
                    url: '/oms-web/examines/'+big_data.deviceType+'/'+big_data.deviceCode+'/'+big_data.reportName+'/'+big_data.recordNo+'/authority?token='+ token,
                    // url: '/oms-web/examines/'+examine_type+'/'+examine_code+'/'+examine_name+'/initialize/authority?token='+ token,
                    dataType:"json",  
                    type:"get", 
                    contentType:"application/json",
                    success:function(data){
                        if(data.code === 0){

                            $("input[name='report']").val(data.data.report);
                            $("input[name='auditors']").val(data.data.auditors);
                            $("input[name='datetime']").val(data.data.datetime);
                            $("input[name='experimenter']").val(data.data.experimenter);
                            
                            experimentMap_check = data.data;
                            $('#Myloading').remove();
                            var ind = 0;
                            for(var key in data.data.experimentMap){
                                 ind ++; 
                                 html_title += '<li>'+key+'</li>';
                                 html_content += '<div class="layui-tab-item"><div class="layui-tab layui-tab-card" lay-filter="tab-all2"><ul class="layui-tab-title" id="uu_'+ind+'"></ul><div class="layui-tab-content" id="mk_'+ind+'"><div class="layui-tab-item"><table class="layui-hide" id="HcurrentTableId_'+ind+'" lay-filter="currentTableFilter"></table></div></div></div></div>';
                            }
                            experimentMap = data.data.experimentMap ;
                               $("#html_content").html(html_content);
                               $("#html_title").html(html_title);
                            //   //  默认显示第一个tab
                            //   $("#html_title").children(":first").addClass('layui-this');
                           
                            //   点击展开首个
                              $("#html_title").children(":first").click();

                              $("#html_content").children(":first").addClass('layui-show');

                        }else{
                            layer.msg(data.msg,{icon: 1,time:1000});
                        }
                },
                    error:function () {
                        layer.msg("Data request error!");
                    }
            });

// 根据表头  切换表格
            ele.on('tab(tab-all)',function(data){
                var reportName = $(this).text();
                sessionStorage.setItem('Hsavecheck_1name',$(this).text())
                var num = 0;
                for(var key in experimentMap){
                    var html_title2 = '';
                    num ++;
                        for(var item in experimentMap[key]){
                            if(key == reportName){
                                html_title2 += '<li>'+item+'</li>'; 
                        }
                    }
                    var uu_id = '#uu_'+num;
                    $(uu_id).html(html_title2);
                    $(uu_id).children(":first").click();
                }
            })

            ele.on('tab(tab-all2)',function(data){
                    var reportName = sessionStorage.getItem('Hsavecheck_1name');
                    sessionStorage.setItem('Hsavecheck_2name',$(this).text())
                    var name_two =$(this).text();
                                    var iu = 0;
                                    for(var x in experimentMap){
                                        iu++
                                       if(reportName == x){
                                            for(var n in experimentMap[x]){
                                                if(name_two == n){
                                                    examine_content_2(experimentMap[x][n],iu)
                                                }
                                            }
                                       }
                                        
                                    }
                      });


// 表格
            function examine_content_2(reportName,iu){
                
                var elem_id = '#HcurrentTableId_'+iu;
                var tab_id = "#mk_"+iu;
                $(tab_id).children(":first").addClass('layui-show');
                
                        table.render({
                            elem: elem_id,
                            data:reportName,
                            toolbar: '#toolbarDemo',  
                            parseData: function(res){ //res 即为原始返回的数据
                                    return {
                                    "code": res.code, //解析接口状态
                                    "msg": res.msg, //解析提示文本
                                    "count": res.data.total, //解析数据长度
                                    "data": res.data.list //解析数据列表
                                }},
                            defaultToolbar: ['filter', 'exports', 'print', {
                                title: '提示',
                                layEvent: 'LAYTABLE_TIPS',
                                icon: 'layui-icon-tips'
                            }],
                            
                            cols: [[
                                //复选框 {type: "checkbox", width: 50, fixed: "left"},
                                {type: 'numbers', width: 120, title: 'S/N', align: "center"},
                                {field: 'name', minWidth: 110, title: 'Data name', align: "center"},
                                {field: 'value', minWidth: 110, title: 'value', align: "center",edit:'text'},
                                {field: 'unit', minWidth: 110, title: 'Company', align: "center"},
                                {field: 'remarks', title: 'remarks', minWidth: 110, align: 'center'},
                                {title: 'operation', width: 150, templet: '#currentTableBar', fixed: "right", align: "center"}
                            ]],
                            limits: [10, 15, 20, 25, 50, 100],
                            limit: 15,
                            page: false,
                            done:function(res){
                                // 表格渲染完成回调
                            }
                        });  
                 }

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {    
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
        });

        // 获取列表data
        table.on('tool(currentTableFilter)', function (obj) {
                sessionStorage.setItem('HsaveItemName',obj.data.name)
                layer.open({
                    title: 'Data curve',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: ['./examine_line.html']
                    });
        });

    });


</script>


</body>
</html>